package com.lasun.server;

import java.util.Iterator;
import java.util.Map;

import com.lasun.server.entity.Client;
import com.lasun.server.entity.World;

public class PacketHandler  {
	
	public void handle(Object msg) {
		Long l = System.currentTimeMillis();
		Map<Integer,Client> clients = World.getWorld().getClients();
		int i = 1;
		for(Iterator<Integer> it=clients.keySet().iterator(); it.hasNext();){   
			int key = (Integer)it.next();
			Client c = clients.get(key);
			if(c.getChannel().isActive()){
				c.sendChatMessage(msg+"");
			}else{
				World.getWorld().unregister(c.getChannel().hashCode());
				continue;
			}
//			c.sendChatMessage(msg + " : " + c.getId());
			if(i%1000==0){
				System.out.println("发出消息数: "+i);
			}
			i++;
        }
		Long l2 = System.currentTimeMillis();
		System.out.println("发送消息总时间："+(l2-l));
	}
}